home *** CD-ROM | disk | FTP | other *** search
/ Aminet 2 / Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso / Aminet / comm / term / term34Source.lha / EmulationPanel.c < prev    next >
C/C++ Source or Header  |  1993-07-16  |  11KB  |  389 lines

  1. /*
  2. **    EmulationPanel.c
  3. **
  4. **    Editing panel for emulation configuration
  5. **
  6. **    Copyright © 1990-1993 by Olaf `Olsen' Barthel & MXM
  7. **        All Rights Reserved
  8. */
  9.  
  10. #include "termGlobal.h"
  11.  
  12. enum    {    GAD_CURSORKEYS, GAD_NUMKEYPAD, GAD_WRAPCURSOR, GAD_WRAPCHARACTERS,
  13.         GAD_CLS_RESETS_CURSOR,GAD_INSERTMODE, GAD_NEWLINE, GAD_FONTSCALE, GAD_SCROLLING,
  14.         GAD_DESTRUCTIVE_BACKSPACE, GAD_SWAP_BS_DEL, GAD_PRINTER_CONTROL,
  15.         GAD_ANSWERBACK, GAD_USE, GAD_CANCEL, GAD_DEFAULT };
  16.  
  17. STATIC STRPTR    ControlMode[3],
  18.         ScrollMode[3],
  19.         ScaleFontText[3];
  20.  
  21. STATIC struct Gadget *
  22. CreateAllGadgets(struct Configuration *Config,struct Gadget *GadgetArray[],struct Gadget **GadgetList,BYTE *Default)
  23. {
  24.     struct Gadget        *Gadget;
  25.     struct NewGadget     NewGadget;
  26.     UWORD             Counter = 0;
  27.  
  28.     SZ_SizeSetup(Window -> WScreen,&UserFont,TRUE);
  29.  
  30.     LocalizeString(ControlMode,MSG_EMULATIONPANEL_STANDARD_MODE_TXT,MSG_EMULATIONPANEL_APPLICATION_MODE_TXT);
  31.     LocalizeString(ScaleFontText,MSG_EMULATIONPANEL_NORMAL_SCALE_TXT,MSG_EMULATIONPANEL_HALF_WIDTH_TXT);
  32.     LocalizeString(ScrollMode,MSG_EMULATIONPANEL_JUMP_TXT,MSG_EMULATIONPANEL_SMOOTH_TXT);
  33.  
  34.     memset(&NewGadget,0,sizeof(struct NewGadget));
  35.  
  36.     if(Gadget = CreateContext(GadgetList))
  37.     {
  38.         SZ_AddLeftOffset(SZ_LeftOffsetDelta(MSG_EMULATIONPANEL_CURSOR_KEYS_GAD,MSG_EMULATIONPANEL_ANSWERBACK_MESSAGE_GAD));
  39.  
  40.         SZ_ResetMaxWidth();
  41.  
  42.         SZ_UpdateMaxWidth(CYCLE_KIND,NULL,0,ControlMode);
  43.         SZ_UpdateMaxWidth(CYCLE_KIND,NULL,0,ScrollMode);
  44.         SZ_UpdateMaxWidth(CYCLE_KIND,NULL,0,ScaleFontText);
  45.         SZ_UpdateMaxWidth(STRING_KIND,NULL,20,NULL);
  46.  
  47.         SZ_SetWidth(SZ_ResetMaxWidth());
  48.  
  49.         NewGadget . ng_GadgetText    = LocaleString(MSG_EMULATIONPANEL_CURSOR_KEYS_GAD);
  50.         NewGadget . ng_GadgetID        = Counter;
  51.  
  52.         GadgetArray[Counter++] = Gadget = CreateGadget(CYCLE_KIND,Gadget,&NewGadget,
  53.             SZ_Adjust,    TRUE,
  54.             SZ_AutoWidth,    TRUE,
  55.  
  56.             GTCY_Labels,    ControlMode,
  57.             GTCY_Active,    Config -> EmulationConfig -> CursorMode,
  58.         TAG_DONE);
  59.  
  60.         NewGadget . ng_GadgetText    = LocaleString(MSG_EMULATIONPANEL_NUMERIC_KEYPAD_GAD);
  61.         NewGadget . ng_GadgetID        = Counter;
  62.  
  63.         GadgetArray[Counter++] = Gadget = CreateGadget(CYCLE_KIND,Gadget,&NewGadget,
  64.             SZ_Adjust,    TRUE,
  65.             SZ_AutoWidth,    TRUE,
  66.  
  67.             GTCY_Labels,    ControlMode,
  68.             GTCY_Active,    Config -> EmulationConfig -> NumericMode,
  69.         TAG_DONE);
  70.  
  71.         NewGadget . ng_GadgetText    = LocaleString(MSG_EMULATIONPANEL_WRAP_CURSOR_MOVES_GAD);
  72.         NewGadget . ng_GadgetID        = Counter;
  73.  
  74.         GadgetArray[Counter++] = Gadget = CreateGadget(CHECKBOX_KIND,Gadget,&NewGadget,
  75.             SZ_Adjust,    TRUE,
  76.             SZ_AutoWidth,    TRUE,
  77.  
  78.             GTCB_Checked,    Config -> EmulationConfig -> CursorWrap,
  79.         TAG_DONE);
  80.  
  81.         NewGadget . ng_GadgetText    = LocaleString(MSG_EMULATIONPANEL_WRAP_CHARACTERS_GAD);
  82.         NewGadget . ng_GadgetID        = Counter;
  83.  
  84.         GadgetArray[Counter++] = Gadget = CreateGadget(CHECKBOX_KIND,Gadget,&NewGadget,
  85.             SZ_Adjust,    TRUE,
  86.             SZ_AutoWidth,    TRUE,
  87.  
  88.             GTCB_Checked,    Config -> EmulationConfig -> LineWrap,
  89.         TAG_DONE);
  90.  
  91.         NewGadget . ng_GadgetText    = LocaleString(MSG_EMULATIONPANEL_CLS_RESETS_CURSOR_GAD);
  92.         NewGadget . ng_GadgetID        = Counter;
  93.  
  94.         GadgetArray[Counter++] = Gadget = CreateGadget(CHECKBOX_KIND,Gadget,&NewGadget,
  95.             SZ_Adjust,    TRUE,
  96.             SZ_AutoWidth,    TRUE,
  97.  
  98.             GTCB_Checked,    Config -> EmulationConfig -> CLSResetsCursor,
  99.         TAG_DONE);
  100.  
  101.         NewGadget . ng_GadgetText    = LocaleString(MSG_EMULATIONPANEL_INSERT_MODE_GAD);
  102.         NewGadget . ng_GadgetID        = Counter;
  103.  
  104.         GadgetArray[Counter++] = Gadget = CreateGadget(CHECKBOX_KIND,Gadget,&NewGadget,
  105.             SZ_Adjust,    TRUE,
  106.             SZ_AutoWidth,    TRUE,
  107.  
  108.             GTCB_Checked,    Config -> EmulationConfig -> InsertMode,
  109.         TAG_DONE);
  110.  
  111.         NewGadget . ng_GadgetText    = LocaleString(MSG_EMULATIONPANEL_NEW_LINE_MODE_GAD);
  112.         NewGadget . ng_GadgetID        = Counter;
  113.  
  114.         GadgetArray[Counter++] = Gadget = CreateGadget(CHECKBOX_KIND,Gadget,&NewGadget,
  115.             SZ_Adjust,    TRUE,
  116.             SZ_AutoWidth,    TRUE,
  117.  
  118.             GTCB_Checked,    Config -> EmulationConfig -> NewLineMode,
  119.         TAG_DONE);
  120.  
  121.         NewGadget . ng_GadgetText    = LocaleString(MSG_EMULATIONPANEL_FONT_SCALE_GAD);
  122.         NewGadget . ng_GadgetID        = Counter;
  123.  
  124.         GadgetArray[Counter++] = Gadget = CreateGadget(CYCLE_KIND,Gadget,&NewGadget,
  125.             SZ_Adjust,    TRUE,
  126.             SZ_AutoWidth,    TRUE,
  127.  
  128.             GTCY_Labels,    ScaleFontText,
  129.             GTCY_Active,    Config -> EmulationConfig -> FontScale,
  130.         TAG_DONE);
  131.  
  132.         NewGadget . ng_GadgetText    = LocaleString(MSG_EMULATIONPANEL_SMOOTH_SCROLLING_GAD);
  133.         NewGadget . ng_GadgetID        = Counter;
  134.  
  135.         GadgetArray[Counter++] = Gadget = CreateGadget(CYCLE_KIND,Gadget,&NewGadget,
  136.             SZ_Adjust,    TRUE,
  137.             SZ_AutoWidth,    TRUE,
  138.  
  139.             GTCY_Labels,    ScrollMode,
  140.             GTCY_Active,    Config -> EmulationConfig -> ScrollMode,
  141.         TAG_DONE);
  142.  
  143.         NewGadget . ng_GadgetText    = LocaleString(MSG_EMULATIONPANEL_DESTRUCTIVE_BACKSPACE_GAD);
  144.         NewGadget . ng_GadgetID        = Counter;
  145.  
  146.         GadgetArray[Counter++] = Gadget = CreateGadget(CHECKBOX_KIND,Gadget,&NewGadget,
  147.             SZ_Adjust,    TRUE,
  148.             SZ_AutoWidth,    TRUE,
  149.  
  150.             GTCB_Checked,    Config -> EmulationConfig -> DestructiveBackspace,
  151.         TAG_DONE);
  152.  
  153.         NewGadget . ng_GadgetText    = LocaleString(MSG_EMULATIONPANEL_SWAP_BS_AND_DEL_GAD);
  154.         NewGadget . ng_GadgetID        = Counter;
  155.  
  156.         GadgetArray[Counter++] = Gadget = CreateGadget(CHECKBOX_KIND,Gadget,&NewGadget,
  157.             SZ_Adjust,    TRUE,
  158.             SZ_AutoWidth,    TRUE,
  159.  
  160.             GTCB_Checked,    Config -> EmulationConfig -> SwapBSDelete,
  161.         TAG_DONE);
  162.  
  163.         NewGadget . ng_GadgetText    = LocaleString(MSG_EMULATIONPANEL_PRINTER_CONTROL_GAD);
  164.         NewGadget . ng_GadgetID        = Counter;
  165.  
  166.         GadgetArray[Counter++] = Gadget = CreateGadget(CHECKBOX_KIND,Gadget,&NewGadget,
  167.             SZ_Adjust,    TRUE,
  168.             SZ_AutoWidth,    TRUE,
  169.  
  170.             GTCB_Checked,    Config -> EmulationConfig -> PrinterEnabled,
  171.         TAG_DONE);
  172.  
  173.         NewGadget . ng_GadgetText    = LocaleString(MSG_EMULATIONPANEL_ANSWERBACK_MESSAGE_GAD);
  174.         NewGadget . ng_GadgetID        = Counter;
  175.  
  176.         GadgetArray[Counter++] = Gadget = CreateGadget(STRING_KIND,Gadget,&NewGadget,
  177.             SZ_Adjust,    TRUE,
  178.             SZ_AutoWidth,    TRUE,
  179.  
  180.             GTST_MaxChars,    79,
  181.             GTST_String,    Config -> EmulationConfig -> AnswerBack,
  182.         TAG_DONE);
  183.  
  184.         SZ_UpdateMaxWidth(BUTTON_KIND,LocaleString(MSG_GLOBAL_USE_GAD),0,NULL);
  185.         SZ_UpdateMaxWidth(BUTTON_KIND,LocaleString(MSG_GLOBAL_CANCEL_GAD),0,NULL);
  186.         SZ_UpdateMaxWidth(BUTTON_KIND,LocaleString(MSG_GLOBAL_DEFAULT_GAD),0,NULL);
  187.  
  188.         SZ_SetWidth(SZ_ResetMaxWidth());
  189.  
  190.         NewGadget . ng_GadgetText    = LocaleString(MSG_GLOBAL_USE_GAD);
  191.         NewGadget . ng_GadgetID        = Counter;
  192.         NewGadget . ng_Flags        = 0;
  193.  
  194.         GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
  195.             SZ_AlignExtra,    TRUE,
  196.             SZ_Adjust,    TRUE,
  197.             SZ_AutoWidth,    TRUE,
  198.             SZ_AlignLeft,    TRUE,
  199.         TAG_DONE);
  200.  
  201.         NewGadget . ng_GadgetText    = LocaleString(MSG_GLOBAL_CANCEL_GAD);
  202.         NewGadget . ng_GadgetID        = Counter;
  203.  
  204.         GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
  205.             SZ_Adjust,    TRUE,
  206.             SZ_AutoWidth,    TRUE,
  207.             SZ_AlignRight,    TRUE,
  208.         TAG_DONE);
  209.  
  210.         if(Default)
  211.         {
  212.             NewGadget . ng_GadgetText    = LocaleString(MSG_GLOBAL_DEFAULT_GAD);
  213.             NewGadget . ng_GadgetID        = Counter;
  214.  
  215.             GadgetArray[Counter] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
  216.                 SZ_Adjust,    TRUE,
  217.                 SZ_AutoWidth,    TRUE,
  218.                 SZ_AlignCentre,    TRUE,
  219.             TAG_DONE);
  220.         }
  221.     }
  222.  
  223.     return(Gadget);
  224. }
  225.  
  226. BYTE
  227. EmulationPanel(struct Configuration *Config,BYTE *Default)
  228. {
  229.     struct Window    *PanelWindow;
  230.     struct Gadget    *GadgetList;
  231.     struct Gadget    *GadgetArray[GAD_DEFAULT + 1];
  232.     BYTE         Changed = FALSE;
  233.  
  234.     SaveConfig(Config,PrivateConfig);
  235.  
  236.     if(CreateAllGadgets(Config,GadgetArray,&GadgetList,Default))
  237.     {
  238.         if(PanelWindow = OpenWindowTags(NULL,
  239.             WA_Left,    GetScreenLeft(Window) + (GetScreenWidth(Window) - SZ_GetWindowWidth()) / 2,
  240.             WA_Top,        GetScreenTop(Window) + (GetScreenHeight(Window) - SZ_GetWindowHeight())    / 2,
  241.             WA_Width,    SZ_GetWindowWidth(),
  242.             WA_Height,    SZ_GetWindowHeight(),
  243.  
  244.             WA_Activate,    TRUE,
  245.             WA_DragBar,    TRUE,
  246.             WA_DepthGadget,    TRUE,
  247.             WA_RMBTrap,    TRUE,
  248.             WA_DepthGadget,    TRUE,
  249.             WA_CloseGadget,    TRUE,
  250.             WA_CustomScreen,Window -> WScreen,
  251.             WA_IDCMP,    IDCMP_CLOSEWINDOW | IDCMP_GADGETDOWN | IDCMP_ACTIVEWINDOW | IDCMP_VANILLAKEY | IDCMP_RAWKEY | STRINGIDCMP | BUTTONIDCMP | CHECKBOXIDCMP | CYCLEIDCMP,
  252.             WA_Title,    LocaleString(MSG_EMULATIONPANEL_EMULATION_PREFERENCES_TXT),
  253.         TAG_DONE))
  254.         {
  255.             struct IntuiMessage    *Massage;
  256.             ULONG             IClass,Code;
  257.             struct Gadget        *Gadget;
  258.             BYTE             Terminated = FALSE;
  259.  
  260.             GuideContext(CONTEXT_EMULATION);
  261.  
  262.             PushWindow(PanelWindow);
  263.  
  264.             AddGList(PanelWindow,GadgetList,(UWORD)-1,(UWORD)-1,NULL);
  265.             RefreshGList(GadgetList,PanelWindow,NULL,(UWORD)-1);
  266.             GT_RefreshWindow(PanelWindow,NULL);
  267.  
  268.             ActiveGadget = NULL;
  269.  
  270.             ClrSignal(SIG_BREAK);
  271.  
  272.             while(!Terminated)
  273.             {
  274.                 if(Wait(PORTMASK(PanelWindow -> UserPort) | SIG_BREAK) & SIG_BREAK)
  275.                 {
  276.                     SaveConfig(PrivateConfig,Config);
  277.  
  278.                     break;
  279.                 }
  280.  
  281.                 while(!Terminated && (Massage = (struct IntuiMessage *)GT_GetIMsg(PanelWindow -> UserPort)))
  282.                 {
  283.                     IClass    = Massage -> Class;
  284.                     Code    = Massage -> Code;
  285.                     Gadget    = (struct Gadget *)Massage -> IAddress;
  286.  
  287.                     GT_ReplyIMsg(Massage);
  288.  
  289.                     KeySelect(GadgetArray,GAD_CANCEL,Code,PanelWindow,&Gadget,&IClass,&Code);
  290.  
  291.                     if(IClass == IDCMP_GADGETDOWN)
  292.                     {
  293.                         if((Gadget -> GadgetType & GTYP_GTYPEMASK) == GTYP_STRGADGET)
  294.                             ActiveGadget = Gadget;
  295.                     }
  296.  
  297.                     if(IClass == IDCMP_ACTIVEWINDOW && ActiveGadget)
  298.                         ActivateGadget(ActiveGadget,PanelWindow,NULL);
  299.  
  300.                     if(IClass == IDCMP_CLOSEWINDOW)
  301.                     {
  302.                         SaveConfig(PrivateConfig,Config);
  303.  
  304.                         Terminated = TRUE;
  305.                     }
  306.  
  307.                     if(IClass == IDCMP_GADGETUP)
  308.                     {
  309.                         switch(Gadget -> GadgetID)
  310.                         {
  311.                             case GAD_USE:
  312.  
  313.                                 Terminated = TRUE;
  314.  
  315.                                 Config -> EmulationConfig -> CursorWrap            = SZ_GetChecked(GadgetArray[GAD_WRAPCURSOR]);
  316.                                 Config -> EmulationConfig -> LineWrap            = SZ_GetChecked(GadgetArray[GAD_WRAPCHARACTERS]);
  317.  
  318.                                 Config -> EmulationConfig -> InsertMode            = SZ_GetChecked(GadgetArray[GAD_INSERTMODE]);
  319.                                 Config -> EmulationConfig -> NewLineMode        = SZ_GetChecked(GadgetArray[GAD_NEWLINE]);
  320.  
  321.                                 Config -> EmulationConfig -> DestructiveBackspace    = SZ_GetChecked(GadgetArray[GAD_DESTRUCTIVE_BACKSPACE]);
  322.                                 Config -> EmulationConfig -> SwapBSDelete        = SZ_GetChecked(GadgetArray[GAD_SWAP_BS_DEL]);
  323.                                 Config -> EmulationConfig -> PrinterEnabled        = SZ_GetChecked(GadgetArray[GAD_PRINTER_CONTROL]);
  324.  
  325.                                 Config -> EmulationConfig -> CLSResetsCursor        = SZ_GetChecked(GadgetArray[GAD_CLS_RESETS_CURSOR]);
  326.  
  327.                                 strcpy(Config -> EmulationConfig -> AnswerBack,SZ_GetString(GadgetArray[GAD_ANSWERBACK]));
  328.  
  329.                                 Changed = TRUE;
  330.  
  331.                                 break;
  332.  
  333.                             case GAD_CANCEL:
  334.  
  335.                                 Terminated = TRUE;
  336.  
  337.                                 SaveConfig(PrivateConfig,Config);
  338.  
  339.                                 break;
  340.  
  341.                             case GAD_DEFAULT:
  342.  
  343.                                 *Default    = TRUE;
  344.  
  345.                                 Terminated    = TRUE;
  346.  
  347.                                 break;
  348.  
  349.                             case GAD_CURSORKEYS:
  350.  
  351.                                 Config -> EmulationConfig -> CursorMode = Code;
  352.                                 break;
  353.  
  354.                             case GAD_NUMKEYPAD:
  355.  
  356.                                 Config -> EmulationConfig -> NumericMode = Code;
  357.                                 break;
  358.  
  359.                             case GAD_FONTSCALE:
  360.  
  361.                                 Config -> EmulationConfig -> FontScale = Code;
  362.                                 break;
  363.  
  364.                             case GAD_SCROLLING:
  365.  
  366.                                 Config -> EmulationConfig -> ScrollMode = Code;
  367.                                 break;
  368.                         }
  369.                     }
  370.                 }
  371.             }
  372.  
  373.             RemoveGList(PanelWindow,GadgetList,(UWORD)-1);
  374.  
  375.             PopWindow();
  376.  
  377.             CloseWindow(PanelWindow);
  378.         }
  379.  
  380.         FreeGadgets(GadgetList);
  381.     }
  382.  
  383.         /* Set up the window size. */
  384.  
  385.     ScreenSizeStuff();
  386.  
  387.     return(Changed);
  388. }
  389.